package edu.gznu.ics.fast.pulsar.controller.prestoacc.taskCtrlController.computeTask;

import edu.gznu.ics.fast.pulsar.model.po.prestoacc.task.computeTask.TaskIdPO;
import edu.gznu.ics.fast.pulsar.model.vo.prestoacc.task.computeTask.TdTaskIdVO;
import edu.gznu.ics.fast.pulsar.model.vo.prestoacc.task.computeTask.parameter.EditTaskParaVO;
import edu.gznu.ics.fast.pulsar.model.vo.user.TdUserVO;
import edu.gznu.ics.fast.pulsar.service.prestoacc.taskService.ComputeTask.ComputeTaskService;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.validation.Valid;
import java.util.List;

/**
 * Created by fei-zyx on 2016/10/15.
 */
@Controller
@RequestMapping("/task")
public class ComputeTaskController {
    @Autowired
    ComputeTaskService computeTaskService;

    @RequestMapping(method = RequestMethod.POST, value = "/checkComputeStates", produces = "application/json;charset=UTF-8")
    public String StartNewTask(@ModelAttribute @Valid TdUserVO tdUserVO, BindingResult result) {
        computeTaskService.checkComputeStatus();
        //computeTaskService.setControlFieldsValid(1);
        //startComputeTaskService.startComputeTask();
        return "";
    }

    @RequestMapping(method = RequestMethod.POST, value = "/staTask", produces = "application/json;charset=UTF-8")
    public String StartTask(@ModelAttribute @Valid TdUserVO tdUserVO, BindingResult result) {
        computeTaskService.checkComputeStatus();
        computeTaskService.setControlFieldsValid(1);
        computeTaskService.startComputeTask();
        //startComputeTaskService.;
        return "";
    }

    @RequestMapping(value = {"/addnewTaskId"})
    public String ApplyNewTask(@ModelAttribute @Valid TdUserVO tdUserVO, BindingResult result) {
        computeTaskService.addNewTaskId();
        // computeTaskService.addNewTaskList();
        return "success";
    }

    @RequestMapping(value = {"/showTaskIdList"})
    public List<TaskIdPO> showTaskIdList(@ModelAttribute @Valid TdUserVO tdUserVO, BindingResult result) {
        return computeTaskService.findAllTaskId();
    }

    @RequestMapping(value = {"/taskReCheck"})
    public String taskReCheck(@ModelAttribute @Valid TdUserVO tdUserVO, BindingResult result) {
        computeTaskService.findAllTaskIdByUser(tdUserVO);
        return "success";
    }
}
